<?php

	// TITLE: Donor AUTO MODEL
	// FILE: scaffolding/model/donor.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createDonor = function($con, $donor) {
		$sql = 'INSERT INTO donor (donation_id, person_id) VALUES (';
		$sql .= $donor->getDonationId() . ', ';
		$sql .= $donor->getPersonId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readDonor = function($con, $id) {
		$sql = 'SELECT * FROM donor WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$donor = new Donor();
			$donor->setDonationId($dbio->select($readDonation(result[0])));
			$donor->setPersonId($dbio->select($readPerson(result[1])));
		} else {
			$donor = false;
		}
		return $donor;
	};

	$updateDonor = function($con, $donor) {
		$sql = 'UPDATE donor SET ';
		$sql .= 'donation_id = ' . $donor->getDonationId() . ', ';
		$sql .= 'person_id = ' . $donor->getPersonId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteDonor = function($con, $id) {
		$sql = 'DELETE FROM donor WHERE donation_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listDonor = function($con) {
		$sql = 'SELECT * FROM donor';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$donors = array();
			while ($result = mysqli_fetch_array($results)) {
				$donor = new Donor();
				$donor->setDonationId($dbio->select($readDonation(result[0])));
				$donor->setPersonId($dbio->select($readPerson(result[1])));
				$donors[] = donor;
			}// end while
		} else {
			$donors = false;
		}
		return $donors;
	};

